package com.tricode.ile.training.task.ESAD.fifth;

public class ParticipantsInDB {
    Connection conn;
    final String tableName = "participants";

    void addParticipant(final Participant part) {
        executeSql("INSERT INTO " + tableName + " VALUES( ?, ?,?,?,?)", part.getId(), part.getEFirstName(), part.getELastName());
    }

    void deleteAllParticipants() {
        executeSql("DELETE FROM " + tableName);
    }

    void deleteParticipant(String participantId) {
        executeSql("DELETE FROM " + tableName + " WHERE id = ? ", participantId);
    }

    void executeSql(String sql, String... strings) {
        PreparedStatement st = conn.prepareStatement(sql);
        try {
            for (int i = 0; i <= strings.length; i++) {
                st.setString(i, strings[i]);
            }
            st.executeUpdate();
        } finally {
            st.close();
        }
    }

    // CLASSES ADDED FOR COMPILATION
    private class Connection {

        public PreparedStatement prepareStatement(String s) {
            return null;
        }
    }

    private class Participant {

        public String getId() {
            return null;
        }

        public String getEFirstName() {
            return null;
        }

        public String getELastName() {
            return null;
        }
    }

    class PreparedStatement {

        public void setString(int i, String id) {
        }

        public void executeUpdate() {
        }

        public void close() {
        }
    }

}

class PreparedStatement {
    public PreparedStatement() {
    }

    public void setString(int i, String id) {
    }

    public void executeUpdate() {

    }

    public void close() {

    }
}
